public class CapacityController{
    
    List<Capacity__c> capacities{get; set;}
    Session__c session;
    
    public CapacityController(ApexPages.StandardController stdController){
        session = (Session__c)stdController.getRecord();
        capacities = [SELECT Id, Name, Session__c FROM Capacity__c 
                WHERE Session__c =: session.id];
        session.Capacity__c = getTotalCapacities();
    }
    
    public Integer getTotalCapacities(){
        return capacities.size();
    }
}